// Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"

println("Hello Swift")

//常量，不可变
let maxNum = 1000

//变量，可变
var index = 0

index = 2

var x = 0.0 , y = 0.0 , z = 0.0

//type safety
//index = "test"

var websiteName:String
websiteName = "oa.jiuan.com"

var red , green , blue : Double

//Int Double Float String

let decimalInt:Int = 17             //十进制
let binaryInt:Int = 0b10001         //二进制
let octalInt:Int = 0o21             //八进制
let hexadecimalInt:Int = 0x11       //十六进制

//科学计数法
let float_a = 0.012
let float_b = 1.2e-2

let bignum_a = 1000000
let bignum_b = 1_000_000
let bignum_c = 1_0000_0000

let num_a:Float = 1
//let num_b:Int = 1.2 //Error

let a:Int = 3
let b:Double = 0.1415926
//let pi:Double = a + b //Error
let pi:Double = Double(a) + b

let 姓名 = "九安医疗"

姓名 + ", 你好"

//BOOL

let imtrue = true
let imfalse = false

if imfalse
{
    println("I am True")
}
else if 3+4==7
{
    println("3+4==7!")
}
else
{
    println("I am False")
}

var m:Int = 1
if m == 1
{
    println("I am True")
}

//元组

let registrationResult = ( true , "九安医疗" , "iHealth")
let registrationResult1 = ( isregistrationSuccess:true , nickname:"九安医疗" , subname:"iHealth")
let connectionResult = (404 , "Not Found")

//以registrationResult为例

let (isregistrationSuccess , nickname , subname) = registrationResult
isregistrationSuccess
nickname
subname

registrationResult.0
registrationResult.1
registrationResult.2


registrationResult1.isregistrationSuccess
registrationResult1.nickname
registrationResult1.subname

//使用下划线（_）忽略部分数值

let loginResult:( Bool , String ) = ( true , "九安医疗" )
let ( isLoginSuccess , _ ) = loginResult
if isregistrationSuccess
{
    println("成功！")
}


//可选值

var q:Int
q = 1

var imOptionalVar:Int?
imOptionalVar = 12

let userInput = "18"
var age = userInput.toInt()

if age != nil
{
    println("your age is \(age!)")
    println("your age is " + String(age!) )
    age
    age!
}
else
{
    println("Invalidate userInput")
}

//Optional Binding
if let userAge = userInput.toInt()
{
    println("your age is \(userAge)")
    userAge
}
else
{
    println("Invalidate userInput")
}

let strA:String? = "test"
strA
strA!

let strB:String! = "test"
strB


































